package com.example.wangzh.mytest.view.path_animator;

import android.animation.TypeEvaluator;

public class PathEvaluate implements TypeEvaluator<PathPoint> {
    @Override
    public PathPoint evaluate(float t, PathPoint startValue, PathPoint endValue) {
        float x = 0, y = 0;
        if (endValue.getmOperation() == PathPoint.CUBIC) {
            float oneMinusT = 1 - t;
            x = oneMinusT * oneMinusT * oneMinusT * startValue.getmX()
                    + 3 * oneMinusT * oneMinusT * t * endValue.getmControl0X()
                    + 3 * oneMinusT * t * t * endValue.getmControl1X()
                    + t * t * t * endValue.getmX();
            y = oneMinusT * oneMinusT * oneMinusT * startValue.getmY()
                    + 3 * oneMinusT * oneMinusT * t * endValue.getmControl0Y()
                    + 3 * oneMinusT * t * t * endValue.getmControl1Y()
                    + t * t * t * endValue.getmY();
        } else if (endValue.getmOperation() == PathPoint.LINE) {
            x = startValue.getmX() + t * (endValue.getmX() - startValue.getmX());
            y = startValue.getmY() + t * (endValue.getmY() - startValue.getmY());
        } else if (endValue.getmOperation() == PathPoint.MOVE) {
            x = endValue.getmX();
            y = endValue.getmY();
        }
        return new PathPoint(PathPoint.MOVE, x, y);
    }
}
